﻿/**
 * @brief    鏂囦欢璺緞鎿嶄綔绫?
 * @details  鏂囦欢鐨勫銆佸垹銆佹敼銆佹煡鎿嶄綔
 * @author   Yin
 * @version  1.0
 * @date
 * @copyright
 * @note 澶囨敞锛氳嫳鏂囨枃浠惰矾寰勪笉鍖哄垎澶у皬鍐?
 */

#ifndef FILEPATHUTILS_H
#define FILEPATHUTILS_H

#include "common_global.h"

#include <QObject>

namespace Common {

	class COMMONSHARED_EXPORT FilePathUtils : public QObject
	{
		Q_OBJECT
	public:
		explicit FilePathUtils(QObject *parent = nullptr);
		~FilePathUtils();

	public:
		/**
		 * @brief   isExist 鍒ゆ柇璺緞鏄惁瀛樺湪锛?
		 * @param   path 鐩綍鎴栬€呮枃浠?
		 * @return  bool true-瀛樺湪, false-鏂囦欢澶逛笉瀛樺湪
		 * @note    鍙傛暟璇存槑锛氳緭鍏ュ弬鏁版枃浠舵垨鑰呮枃浠剁洰褰?
		 */
		static bool isExist(QString path);

		/**
		 * @brief   isExistFile 鍒ゆ柇鏂囦欢鏄惁瀛樺湪
		 * @param   path 璺緞
		 * @return  bool true-瀛樺湪, false-鏂囦欢澶逛笉瀛樺湪
		 */
		static bool isExistFile(QString path);

		/**
		 * @brief   isDir 鍒ゆ柇鏂囦欢鐩綍鏄惁瀛樺湪
		 * @param   path  璺緞
		 * @return  bool  true-瀛樺湪, false-鏂囦欢澶逛笉瀛樺湪
		 */
		static bool isExistDir(QString path);

		/**
		 * @brief   isDriver 鍒ゆ柇鏄惁鏄牴鐩綍
		 * @param   path 璺緞
		 * @return  bool  true-瀛樺湪, false-鏂囦欢澶逛笉瀛樺湪
		 * @note    鍙傛暟绀轰緥锛欶:/
		 */
		static bool isRoot(QString path);

		/**
		 * @brief   isEmpty 鍒ゆ柇鏄惁涓虹┖
		 * @param   path 璺緞 鍙互涓烘枃浠剁洰褰曟垨鑰呮枃浠?
		 * @return  bool  true-鏂囦欢鐩綍鎴栬€呮枃浠朵负绌? false-鏂囦欢鐩綍鎴栬€呮枃浠朵笉涓虹┖
		 */
		static bool isEmpty(QString path);

		/**
		 * @brief   removeDir 鍒犻櫎鏂囦欢鐩綍
		 * @param   path 璺緞
		 * @return  bool true-鍒犻櫎鎴愬姛, false-鍒犻櫎澶辫触
		 * note     鍔熻兘璇存槑锛氬垹闄ょ洰褰曪紝鍙婂瓙鐩綍鍜屾墍鏈夋枃浠躲€?
		 */
		static bool removeDir(QString path);

		/**
		 * @brief   removeFile 鍒犻櫎鏂囦欢
		 * @param   fileName 璺緞
		 * @return  bool true-鍒犻櫎鎴愬姛, false-鍒犻櫎澶辫触
		 * @note    鍔熻兘璇存槑锛氬垹闄ゅ彧閽堝鏂囦欢
		 */
		static bool removeFile(QString fileName);

		/**
		 * @brief   鏂囦欢閲嶆柊鍛藉悕
		 * @param   oldName  闇€瑕侀噸鍛藉悕鐨勬枃浠惰矾寰?
		 * @param   newName  鏂版枃浠跺悕璺緞
		 * @return  bool   true - 閲嶆柊鍛藉悕鎴愬姛锛宖alse - 閲嶆柊鍛藉悕鎴愬姛
		 * @note    鏂囦欢蹇呴』鍦ㄥ悓涓€鏂囦欢澶逛笅锛屽惁鍒欏け璐?
		 */
		static bool rename(QString from, QString to);

		/**
		 * @brief   copyFile 澶嶅埗鏂囦欢
		 * @param   from 闇€瑕佸鍒剁殑鏂囦欢
		 * @param   to  澶嶅埗鐩爣璺緞
		 * @param   overwriteFile   鑻ョ洰鏍囨枃浠朵笅瀛樺湪鐩稿悓鏂囦欢鏄惁瑕嗙洊
		 * @return  bool true - 澶嶅埗鎴愬姛锛宖alse - 澶嶅埗鎴愬姛
		 */
		static bool copyFile(QString from, QString to);

		/**
		 * @brief   copyDir 澶嶅埗鏂囦欢澶?
		 * @param   oldPath 婧愭枃浠惰矾寰?
		 * @param   newPath 鐩爣鏂囦欢璺緞
		 * @param   overwriteFile  鑻ョ洰鏍囨枃浠朵笅瀛樺湪鐩稿悓鏂囦欢鏄惁瑕嗙洊
		 * @return  bool true - 澶嶅埗鎴愬姛锛宖alse - 澶嶅埗鎴愬姛
		 * note     鏀寔澶嶅埗鎵€鏈夋枃浠?鍖呭惈瀛愮洰褰?鍙婂叾 瀛愭枃浠讹級
		 */
		static bool copyDir(QString oldPath, QString newPath, const bool & overwriteFile = false);

		/**
		 * @brief   createDir 鍒涘缓鐩綍
		 * @param   path  璺緞
		 * @return  bool  true - 鍒涘缓鎴愬姛 false - 鍒涘缓澶辫触
		 * @note    鏀寔鍒涘缓澶氱骇鐩綍
		 */
		static bool createDir(QString path);

		/**
		 * @brief   path    parentDir 鑾峰彇涓婁竴绾х洰褰?
		 * @param   path    鏂囦欢璺垨鑰呮枃浠?
		 * @return  QString 杩斿洖涓婁竴绾х洰褰?
		 * @note    鐜版帴鍙ｅ彧鏀寔瀵规枃浠舵垨鏂囦欢鐩綍瀛樺湪鐨勮矾寰勮繘琛屽彇涓婁竴绾х洰褰曪紙鍚庢湡浼氳皟鏁达級
		 */
		static QString parentDir(QString path);

		/**
		 * @brief   path    鑾峰彇鏂囦欢璺緞锛堜笉鍖呭惈鏂囦欢鍚嶏級
		 * @param   path    璺緞
		 * @return  QString
		 * @note    杈撳叆鍙傛暟涓猴細鏂囦欢璺緞锛岃嫢鍙傛暟涓虹洰褰曞垯杩斿洖绌?
					澶囨敞锛氬彧瀵瑰瓧绗︿覆鎿嶄綔锛屼笉鍒ゆ柇鏂囦欢鏄惁瀛樺湪
		 */
		static QString path(QString path);

		/**
		 * @brief   extension  鑾峰彇鏂囦欢鎷撳睍鍚?
		 * @param   path    璺緞
		 * @return  QString 鏂囦欢鎷撳睍鍚?
		 * @note    杈撳叆鍙傛暟涓猴細鏂囦欢璺緞锛岃嫢鍙傛暟涓虹洰褰曞垯杩斿洖绌?
					澶囨敞锛氬彧瀵瑰瓧绗︿覆鎿嶄綔锛屼笉鍒ゆ柇鏂囦欢鏄惁瀛樺湪
		 */
		static QString suffix(QString path);

		/**
		 * @brief   baseName 鑾峰彇鏂囦欢鍚嶏紙涓嶅寘鍚嫇灞曞悕锛?
		 * @param   path    璺緞
		 * @return  QString 鏂囦欢鍚?
		 * @note    杈撳叆鍙傛暟涓猴細鏂囦欢璺緞锛岃嫢鍙傛暟涓虹洰褰曞垯杩斿洖绌?
					澶囨敞锛氬彧瀵瑰瓧绗︿覆鎿嶄綔锛屼笉鍒ゆ柇鏂囦欢鏄惁瀛樺湪
		 */
		static QString baseName(QString path);

		/**
		 * @brief   fileName  鑾峰彇鏂囦欢鍚嶏紙鍖呭惈鎷撳睍鍚嶏級
		 * @param   path      璺緞
		 * @return  QString   鏂囦欢鍚?
		 * @note    杈撳叆鍙傛暟涓猴細鏂囦欢璺緞锛岃嫢鍙傛暟涓虹洰褰曞垯杩斿洖绌?
					澶囨敞锛氬彧瀵瑰瓧绗︿覆鎿嶄綔锛屼笉鍒ゆ柇鏂囦欢鏄惁瀛樺湪
		 */
		static QString fileName(QString path);

		/**
		 * @brief   changeSuffix 淇敼鎵╁睍鍚?
		 * @param   path         鏂囦欢璺緞
		 * @param   newExtension 鏂板悗缂€鍚?
		 * @return  QString  杩斿洖鏂扮殑鏂囦欢璺緞
		 * @note    鍔熻兘璇存槑锛氬瓧绗︿覆鎿嶄綔锛屼笉瀵圭湡瀹炴枃浠舵搷浣?
		 */
		static QString changeSuffix(QString path, QString newExtension);

		/**
		 * @brief   getAllSons 鑾峰彇鏂囦欢澶逛笅鐨勫瓙鏂囦欢鐩綍
		 * @param   path    鏂囦欢璺緞
		 * @param   & sons  鏂囦欢鐩綍鍒楄〃
		 * @return  void
		 * @note    鑾峰彇鏂囦欢鐩綍涓嬬殑鎵€鏈夊瓙鏂囦欢
		 */
		static void getAllSons(QString path, QVector<QString>& sons);

	};

} //namespace Common

#endif // FILEPATHUTILS_H
